// custom-tab-bar/index.ts
import { storeBindingsBehavior } from "mobx-miniprogram-bindings"
import { store } from '../store/store'

const app = getApp()
Component({
    behaviors: [storeBindingsBehavior],
    storeBindings: {
        store,
        fields: {
            active: "activeTabbarIndex"
        },
        actions: {
            updateActive: "updateActiveTabbarIndex"
        }
    },
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        list: [
            {
                "pagePath": "/pages/index/index",
                "text": "首页",
                "iconPath": "../resources/home.png",
                "selectedIconPath": "../resources/home_active.png"
            },
            {
                "pagePath": "/pages/mall/index",
                "text": "商品",
                "iconPath": "../resources/mall.png",
                "selectedIconPath": "../resources/mall_active.png"
            },
            {
                "pagePath": "/pages/cart/cart",
                "text": "购物车",
                "iconPath": "../resources/cart.png",
                "selectedIconPath": "../resources/cart_active.png",
                "info": 3
            },
            {
                "pagePath": "/pages/mine/mine",
                "text": "我的",
                "iconPath": "../resources/mine.png",
                "selectedIconPath": "../resources/mine_active.png",
            }
        ]
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onChange(event: any) {
            // event.detail 的值为当前选中项的索引
            wx.switchTab({
                url: this.data.list[event.detail].pagePath
            })
            this.updateActive(event.detail)
        },
    },
    onShow() {
    }
})
